package to.us.abuzz.jspwikiplugin;

import java.util.Map;

import to.us.abuzz.net.ServerMonitor;

import com.ecyrd.jspwiki.WikiContext;
import com.ecyrd.jspwiki.plugin.PluginException;
import com.ecyrd.jspwiki.plugin.WikiPlugin;

public class ServerStatus implements WikiPlugin {

	@SuppressWarnings("unchecked")
	public String execute(WikiContext arg0, Map map) throws PluginException {
		try {
		String server = (String)map.get("server");
		int port = Integer.parseInt( (String)map.get("port"));
		if (ServerMonitor.checkPort(server, port)) {
			return "<div style=\"background: green;width:12px;height:12px\"></div>";
		}
		return "<div style=\"background: red;width:12px;height:12px\"></div>";
		} catch (Exception e) {
		return "server and port are required parameters; example server = \"ias2xap0.bcs.att.com\", port=\"8081\"";
		}
	}

}
